#pragma once
#include <Windows.h>
#include <string>
#include "CyMessageFilter.h"
#include "CyMessageProcessor.h"
#include "CyDelegate.h"

// Warper for button
class CyGUIButton : public CyMessageFilter
{
private:
	INT _id;
	HWND _hwnd;
	CyDelegate_base * _clickHandler;

public:
	// parentHWND: the handle of the parent that contains the button
	// id: the id of the button
	CyGUIButton(HWND parentHWND, INT id);
	~CyGUIButton(void);

	// Set name for the button
	void SetText(const std::wstring& str);

	// Get name of the button
	// str: the string used to contain the name
	// return: the string above, for convenience
	std::wstring& GetText(std::wstring& str) const;
	
	// set handler for click event
	template <class R> void SetClickHandler(R * obj,
		typename CyDelegate<R>::Handler handler)
	{
		if (obj == NULL || handler == NULL)
		{
			if(_clickHandler != NULL)
				delete _clickHandler;
			_clickHandler = NULL;
		}
		else
		{
			_clickHandler = new typename CyDelegate<R>(obj, handler);
		}
	}

	BOOL HandleMessage(
		HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) override;
};